package com.noble.meether.logic.third.share;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.noble.meether.R;
import com.noble.glamour.module.logic.application.ModuleMgr;
import com.noble.library.utils.qrcode.QRCodeUtil;
import com.noble.library.view.base.BaseDialogFragment;

/**
 * 分享： 二维码弹框
 */
public class QRDialog extends BaseDialogFragment implements View.OnClickListener {
    private ImageView qr_img;

    public QRDialog() {
        initDialog();
    }

    private void initDialog() {
        settWindowAnimations(R.style.AnimDownInDownOutOverShoot);
        setGravity(Gravity.CENTER);
        setDialogSizeRatio(0, 0);
        setCanceledOnTouchOutside(false);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        setContentView(R.layout.share_qr_dialog);
        initView();
        return getContentView();
    }

    private void initView() {
        qr_img = (ImageView) findViewById(R.id.qr_img);
        findViewById(R.id.btn_cancel).setOnClickListener(this);
        findViewById(R.id.btn_close).setOnClickListener(this);

        String inviteUrl = ModuleMgr.getCommonMgr().getSetting().getShareData().getRedirect();
        Bitmap mBitmap = QRCodeUtil.createQRCodeBitmap(inviteUrl, 480, 480);
        qr_img.setImageBitmap(mBitmap);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_cancel:
            case R.id.btn_close:
                dismiss();
                break;
        }
    }
}
